home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / mach / message.h < prev    next >
Text File  |  1995-02-14  |  26KB  |  811 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992-1987 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    message.h,v $
  29.  * Revision 2.15  93/01/14  17:44:53  danner
  30.  *     Cleanup.
  31.  *     [92/06/10            pds]
  32.  *     64bit cleanup.
  33.  *     [92/12/01            af]
  34.  * 
  35.  * Revision 2.14  92/05/21  17:22:30  jfriedl
  36.  *     Appended 'U' to constants that would otherwise be signed.
  37.  *     [92/05/16            jfriedl]
  38.  * 
  39.  * Revision 2.13  92/02/23  14:42:54  elf
  40.  *     Condensed history, update copyright.
  41.  *     [92/02/23            danner]
  42.  * 
  43.  *     Added MACH_MSGH_BITS_MIGRATED (NORMA_IPC internal).
  44.  *     [91/12/25  16:42:44  jsb]
  45.  * 
  46.  * Revision 2.12  92/01/15  13:44:29  rpd
  47.  *     Changed MACH_IPC_COMPAT conditionals to default to not present.
  48.  * 
  49.  * Condensed history:
  50.  *     Check __STDC__ to get function prototypes. (rpd)
  51.  *     Removed MACH_MSGH_KIND_NOTIFICATION compatibility defn. (rpd)
  52.  *     Replaced msgh_kind with msgh_seqno. (jsb)
  53.  *    Added MACH_MSGH_BITS_COMPLEX_{PORTS,DATA}. (jsb)
  54.  *     Changed mach_msg_timeout_t to unsigned. (rpd)
  55.  *    Converted to new IPC (rpd)
  56.  *    Named unused bits in message structures (rpd).
  57.  *    Added MSG_TYPE_POLYMORPHIC (rpd).
  58.  *    Put ownership rights under MACH_IPC_XXXHACK (rpd).
  59.  *     Removed some unused defines (rpd).
  60.  *    Made MSG_TYPE_PORT_NAME a separate type (rpd).
  61.  *    Added SEND_SWITCH (mwyoung).
  62.  *    Added SEND_MSG_SIZE_CHANGE (mwyoung).
  63.  *    Added msg_size_t, msg_timeout_t (mwyoung).
  64.  *    Added MSG_TYPE_INTERNAL_MEMORY (mwyoung).
  65.  *    Use unsigned ints/shorts (avie).
  66.  *    Added SEND_INTERRUPT (mwyoung).
  67.  */
  68. /*
  69.  *    File:    mach/message.h
  70.  *
  71.  *    Mach IPC message and primitive function definitions.
  72.  */
  73.  
  74. #ifndef    _MACH_MESSAGE_H_
  75. #define _MACH_MESSAGE_H_
  76.  
  77. #import <mach/kern_return.h>
  78. #import <mach/port.h>
  79.  
  80.  
  81. /*
  82.  *  The timeout mechanism uses mach_msg_timeout_t values,
  83.  *  passed by value.  The timeout units are milliseconds.
  84.  *  It is controlled with the MACH_SEND_TIMEOUT
  85.  *  and MACH_RCV_TIMEOUT options.
  86.  */
  87.  
  88. typedef natural_t mach_msg_timeout_t;
  89.  
  90. /*
  91.  *  The value to be used when there is no timeout.
  92.  *  (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.)
  93.  */
  94.  
  95. #define MACH_MSG_TIMEOUT_NONE        ((mach_msg_timeout_t) 0)
  96.  
  97. /*
  98.  *  The kernel uses MACH_MSGH_BITS_COMPLEX as a hint.  It it isn't on, it
  99.  *  assumes the body of the message doesn't contain port rights or OOL
  100.  *  data.  The field is set in received messages.  A user task must
  101.  *  use caution in interpreting the body of a message if the bit isn't
  102.  *  on, because the mach_msg_type's in the body might "lie" about the
  103.  *  contents.  If the bit isn't on, but the mach_msg_types
  104.  *  in the body specify rights or OOL data, the behaviour is undefined.
  105.  *  (Ie, an error may or may not be produced.)
  106.  *
  107.  *  The value of MACH_MSGH_BITS_REMOTE determines the interpretation
  108.  *  of the msgh_remote_port field.  It is handled like a msgt_name.
  109.  *
  110.  *  The value of MACH_MSGH_BITS_LOCAL determines the interpretation
  111.  *  of the msgh_local_port field.  It is handled like a msgt_name.
  112.  *
  113.  *  MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote
  114.  *  and local fields, into a single value suitable for msgh_bits.
  115.  *
  116.  *  MACH_MSGH_BITS_COMPLEX_PORTS, MACH_MSGH_BITS_COMPLEX_DATA, and
  117.  *  MACH_MSGH_BITS_CIRCULAR should be zero; they are used internally.
  118.  *
  119.  *  The unused bits should be zero.
  120.  */
  121.  
  122. #define MACH_MSGH_BITS_ZERO        0x00000000
  123. #define MACH_MSGH_BITS_REMOTE_MASK    0x000000ff
  124. #define MACH_MSGH_BITS_LOCAL_MASK    0x0000ff00
  125. #define MACH_MSGH_BITS_COMPLEX        0x80000000U
  126. #define    MACH_MSGH_BITS_CIRCULAR        0x40000000    /* internal use only */
  127. #define    MACH_MSGH_BITS_COMPLEX_PORTS    0x20000000    /* internal use only */
  128. #define    MACH_MSGH_BITS_COMPLEX_DATA    0x10000000    /* internal use only */
  129. #define    MACH_MSGH_BITS_MIGRATED        0x08000000    /* internal use only */
  130. #define    MACH_MSGH_BITS_UNUSED        0x07ff0000
  131.  
  132. #define    MACH_MSGH_BITS_PORTS_MASK                \
  133.         (MACH_MSGH_BITS_REMOTE_MASK|MACH_MSGH_BITS_LOCAL_MASK)
  134.  
  135. #define MACH_MSGH_BITS(remote, local)                \
  136.         ((remote) | ((local) << 8))
  137. #define    MACH_MSGH_BITS_REMOTE(bits)                \
  138.         ((bits) & MACH_MSGH_BITS_REMOTE_MASK)
  139. #define    MACH_MSGH_BITS_LOCAL(bits)                \
  140.         (((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8)
  141. #define    MACH_MSGH_BITS_PORTS(bits)                \
  142.         ((bits) & MACH_MSGH_BITS_PORTS_MASK)
  143. #define    MACH_MSGH_BITS_OTHER(bits)                \
  144.         ((bits) &~ MACH_MSGH_BITS_PORTS_MASK)
  145.  
  146. /*
  147.  *  Every message starts with a message header.
  148.  *  Following the message header are zero or more pairs of
  149.  *  type descriptors (mach_msg_type_t/mach_msg_type_long_t) and
  150.  *  data values.  The size of the message must be specified in bytes,
  151.  *  and includes the message header, type descriptors, inline
  152.  *  data, and inline pointer for out-of-line data.
  153.  *
  154.  *  The msgh_remote_port field specifies the destination of the message.
  155.  *  It must specify a valid send or send-once right for a port.
  156.  *
  157.  *  The msgh_local_port field specifies a "reply port".  Normally,
  158.  *  This field carries a send-once right that the receiver will use
  159.  *  to reply to the message.  It may carry the values MACH_PORT_NULL,
  160.  *  MACH_PORT_DEAD, a send-once right, or a send right.
  161.  *
  162.  *  The msgh_seqno field carries a sequence number associated with the
  163.  *  received-from port.  A port's sequence number is incremented every
  164.  *  time a message is received from it.  In sent messages, the field's
  165.  *  value is ignored.
  166.  *
  167.  *  The msgh_id field is uninterpreted by the message primitives.
  168.  *  It normally carries information specifying the format
  169.  *  or meaning of the message.
  170.  */
  171.  
  172. typedef unsigned int mach_msg_bits_t;
  173. typedef    unsigned int mach_msg_size_t;
  174. typedef natural_t mach_msg_seqno_t;
  175. typedef integer_t mach_msg_id_t;
  176.  
  177. typedef    struct {
  178.     mach_msg_bits_t    msgh_bits;
  179.     mach_msg_size_t    msgh_size;
  180.     mach_port_t        msgh_remote_port;
  181.     mach_port_t        msgh_local_port;
  182.     mach_port_seqno_t    msgh_seqno;
  183.     mach_msg_id_t    msgh_id;
  184. } mach_msg_header_t;
  185.  
  186. /*
  187.  *  There is no fixed upper bound to the size of Mach messages.
  188.  */
  189.  
  190. #define    MACH_MSG_SIZE_MAX    ((mach_msg_size_t) ~0)
  191.  
  192. /*
  193.  *  Compatibility definitions, for code written
  194.  *  when there was a msgh_kind instead of msgh_seqno.
  195.  */
  196.  
  197. #define MACH_MSGH_KIND_NORMAL        0x00000000
  198. #if    0
  199. /* code using this is likely to break, so better not to have it defined */
  200. #define MACH_MSGH_KIND_NOTIFICATION    0x00000001
  201. #endif
  202. #define    msgh_kind            msgh_seqno
  203. #define mach_msg_kind_t            mach_port_seqno_t
  204.  
  205. /*
  206.  *  The msgt_number field specifies the number of data elements.
  207.  *  The msgt_size field specifies the size of each data element, in bits.
  208.  *  The msgt_name field specifies the type of each data element.
  209.  *  If msgt_inline is TRUE, the data follows the type descriptor
  210.  *  in the body of the message.  If msgt_inline is FALSE, then a pointer
  211.  *  to the data should follow the type descriptor, and the data is
  212.  *  sent out-of-line.  In this case, if msgt_deallocate is TRUE,
  213.  *  then the out-of-line data is moved (instead of copied) into the message.
  214.  *  If msgt_longform is TRUE, then the type descriptor is actually
  215.  *  a mach_msg_type_long_t.
  216.  *
  217.  *  The actual amount of inline data following the descriptor must
  218.  *  a multiple of the word size.  For out-of-line data, this is a
  219.  *  pointer.  For inline data, the supplied data size (calculated
  220.  *  from msgt_number/msgt_size) is rounded up.  This guarantees
  221.  *  that type descriptors always fall on word boundaries.
  222.  *
  223.  *  For port rights, msgt_size must be 8*sizeof(mach_port_t).
  224.  *  If the data is inline, msgt_deallocate should be FALSE.
  225.  *  The msgt_unused bit should be zero.
  226.  *  The msgt_name, msgt_size, msgt_number fields in
  227.  *  a mach_msg_type_long_t should be zero.
  228.  */
  229.  
  230. typedef unsigned int mach_msg_type_name_t;
  231. typedef unsigned int mach_msg_type_size_t;
  232. typedef natural_t  mach_msg_type_number_t;
  233.  
  234. typedef struct  {
  235.     unsigned int    msgt_name : 8,
  236.             msgt_size : 8,
  237.             msgt_number : 12,
  238.             msgt_inline : 1,
  239.             msgt_longform : 1,
  240.             msgt_deallocate : 1,
  241.             msgt_unused : 1;
  242. } mach_msg_type_t;
  243.  
  244. typedef    struct    {
  245.     mach_msg_type_t    msgtl_header;
  246.     unsigned short    msgtl_name;
  247.     unsigned short    msgtl_size;
  248.     natural_t        msgtl_number;
  249. } mach_msg_type_long_t;
  250.  
  251.  
  252. /*
  253.  *    Known values for the msgt_name field.
  254.  *
  255.  *    The only types known to the Mach kernel are
  256.  *    the port types, and those types used in the
  257.  *    kernel RPC interface.
  258.  */
  259.  
  260. #define MACH_MSG_TYPE_UNSTRUCTURED    0
  261. #define MACH_MSG_TYPE_BIT        0
  262. #define MACH_MSG_TYPE_BOOLEAN        0
  263. #define MACH_MSG_TYPE_INTEGER_16    1
  264. #define MACH_MSG_TYPE_INTEGER_32    2
  265. #define MACH_MSG_TYPE_CHAR        8
  266. #define MACH_MSG_TYPE_BYTE        9
  267. #define MACH_MSG_TYPE_INTEGER_8        9
  268. #define MACH_MSG_TYPE_REAL        10
  269. #define MACH_MSG_TYPE_INTEGER_64    11
  270. #define MACH_MSG_TYPE_STRING        12
  271. #define MACH_MSG_TYPE_STRING_C        12
  272.  
  273. /*
  274.  *  Values used when sending a port right.
  275.  */
  276.  
  277. #define MACH_MSG_TYPE_MOVE_RECEIVE    16    /* Must hold receive rights */
  278. #define MACH_MSG_TYPE_MOVE_SEND        17    /* Must hold send rights */
  279. #define MACH_MSG_TYPE_MOVE_SEND_ONCE    18    /* Must hold sendonce rights */
  280. #define MACH_MSG_TYPE_COPY_SEND        19    /* Must hold send rights */
  281. #define MACH_MSG_TYPE_MAKE_SEND        20    /* Must hold receive rights */
  282. #define MACH_MSG_TYPE_MAKE_SEND_ONCE    21    /* Must hold receive rights */
  283.  
  284. /*
  285.  *  Values received/carried in messages.  Tells the receiver what
  286.  *  sort of port right he now has.
  287.  *
  288.  *  MACH_MSG_TYPE_PORT_NAME is used to transfer a port name
  289.  *  which should remain uninterpreted by the kernel.  (Port rights
  290.  *  are not transferred, just the port name.)
  291.  */
  292.  
  293. #define MACH_MSG_TYPE_PORT_NAME        15
  294. #define MACH_MSG_TYPE_PORT_RECEIVE    MACH_MSG_TYPE_MOVE_RECEIVE
  295. #define MACH_MSG_TYPE_PORT_SEND        MACH_MSG_TYPE_MOVE_SEND
  296. #define MACH_MSG_TYPE_PORT_SEND_ONCE    MACH_MSG_TYPE_MOVE_SEND_ONCE
  297.  
  298. #define MACH_MSG_TYPE_LAST        22        /* Last assigned */
  299.  
  300. /*
  301.  *  A dummy value.  Mostly used to indicate that the actual value
  302.  *  will be filled in later, dynamically.
  303.  */
  304.  
  305. #define MACH_MSG_TYPE_POLYMORPHIC    ((mach_msg_type_name_t) -1)
  306.  
  307. /*
  308.  *    Is a given item a port type?
  309.  */
  310.  
  311. #define MACH_MSG_TYPE_PORT_ANY(x)            \
  312.     (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) &&        \
  313.      ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
  314.  
  315. #define    MACH_MSG_TYPE_PORT_ANY_SEND(x)            \
  316.     (((x) >= MACH_MSG_TYPE_MOVE_SEND) &&        \
  317.      ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
  318.  
  319. #define    MACH_MSG_TYPE_PORT_ANY_RIGHT(x)            \
  320.     (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) &&        \
  321.      ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE))
  322.  
  323. typedef integer_t mach_msg_option_t;
  324.  
  325. #define MACH_MSG_OPTION_NONE    0x00000000
  326.  
  327. #define    MACH_SEND_MSG        0x00000001
  328. #define    MACH_RCV_MSG        0x00000002
  329.  
  330. #define MACH_SEND_TIMEOUT    0x00000010
  331. #define MACH_SEND_NOTIFY    0x00000020
  332. #define MACH_SEND_INTERRUPT    0x00000040    /* libmach implements */
  333. #define MACH_SEND_CANCEL    0x00000080
  334. #define MACH_RCV_TIMEOUT    0x00000100
  335. #define MACH_RCV_NOTIFY        0x00000200
  336. #define MACH_RCV_INTERRUPT    0x00000400    /* libmach implements */
  337. #define MACH_RCV_LARGE        0x00000800
  338.  
  339. #define MACH_SEND_ALWAYS    0x00010000    /* internal use only */
  340. #define MACH_SEND_SWITCH    0x00020000    /* internal use only */
  341.  
  342.  
  343. /*
  344.  *  Much code assumes that mach_msg_return_t == kern_return_t.
  345.  *  This definition is useful for descriptive purposes.
  346.  *
  347.  *  See <mach/error.h> for the format of error codes.
  348.  *  IPC errors are system 4.  Send errors are subsystem 0;
  349.  *  receive errors are subsystem 1.  The code field is always non-zero.
  350.  *  The high bits of the code field communicate extra information
  351.  *  for some error codes.  MACH_MSG_MASK masks off these special bits.
  352.  */
  353.  
  354. typedef kern_return_t mach_msg_return_t;
  355.  
  356. #define MACH_MSG_SUCCESS        0x00000000
  357.  
  358. #define    MACH_MSG_MASK            0x00003c00
  359.         /* All special error code bits defined below. */
  360. #define    MACH_MSG_IPC_SPACE        0x00002000
  361.         /* No room in IPC name space for another capability name. */
  362. #define    MACH_MSG_VM_SPACE        0x00001000
  363.         /* No room in VM address space for out-of-line memory. */
  364. #define    MACH_MSG_IPC_KERNEL        0x00000800
  365.         /* Kernel resource shortage handling an IPC capability. */
  366. #define    MACH_MSG_VM_KERNEL        0x00000400
  367.         /* Kernel resource shortage handling out-of-line memory. */
  368.  
  369. #define MACH_SEND_IN_PROGRESS        0x10000001
  370.         /* Thread is waiting to send.  (Internal use only.) */
  371. #define MACH_SEND_INVALID_DATA        0x10000002
  372.         /* Bogus in-line data. */
  373. #define MACH_SEND_INVALID_DEST        0x10000003
  374.         /* Bogus destination port. */
  375. #define MACH_SEND_TIMED_OUT        0x10000004
  376.         /* Message not sent before timeout expired. */
  377. #define MACH_SEND_WILL_NOTIFY        0x10000005
  378.         /* Msg-accepted notification will be generated. */
  379. #define MACH_SEND_NOTIFY_IN_PROGRESS    0x10000006
  380.         /* Msg-accepted notification already pending. */
  381. #define MACH_SEND_INTERRUPTED        0x10000007
  382.         /* Software interrupt. */
  383. #define MACH_SEND_MSG_TOO_SMALL        0x10000008
  384.         /* Data doesn't contain a complete message. */
  385. #define MACH_SEND_INVALID_REPLY        0x10000009
  386.         /* Bogus reply port. */
  387. #define MACH_SEND_INVALID_RIGHT        0x1000000a
  388.         /* Bogus port rights in the message body. */
  389. #define MACH_SEND_INVALID_NOTIFY    0x1000000b
  390.         /* Bogus notify port argument. */
  391. #define MACH_SEND_INVALID_MEMORY    0x1000000c
  392.         /* Invalid out-of-line memory pointer. */
  393. #define MACH_SEND_NO_BUFFER        0x1000000d
  394.         /* No message buffer is available. */
  395. #define MACH_SEND_NO_NOTIFY        0x1000000e
  396.         /* Resource shortage; can't request msg-accepted notif. */
  397. #define MACH_SEND_INVALID_TYPE        0x1000000f
  398.         /* Invalid msg-type specification. */
  399. #define MACH_SEND_INVALID_HEADER    0x10000010
  400.         /* A field in the header had a bad value. */
  401.  
  402. #define MACH_RCV_IN_PROGRESS        0x10004001
  403.         /* Thread is waiting for receive.  (Internal use only.) */
  404. #define MACH_RCV_INVALID_NAME        0x10004002
  405.         /* Bogus name for receive port/port-set. */
  406. #define MACH_RCV_TIMED_OUT        0x10004003
  407.         /* Didn't get a message within the timeout value. */
  408. #define MACH_RCV_TOO_LARGE        0x10004004
  409.         /* Message buffer is not large enough for inline data. */
  410. #define MACH_RCV_INTERRUPTED        0x10004005
  411.         /* Software interrupt. */
  412. #define MACH_RCV_PORT_CHANGED        0x10004006
  413.         /* Port moved into a set during the receive. */
  414. #define MACH_RCV_INVALID_NOTIFY        0x10004007
  415.         /* Bogus notify port argument. */
  416. #define MACH_RCV_INVALID_DATA        0x10004008
  417.         /* Bogus message buffer for inline data. */
  418. #define MACH_RCV_PORT_DIED        0x10004009
  419.         /* Port/set was sent away/died during receive. */
  420. #define    MACH_RCV_IN_SET            0x1000400a
  421.         /* Port is a member of a port set. */
  422. #define    MACH_RCV_HEADER_ERROR        0x1000400b
  423.         /* Error receiving message header.  See special bits. */
  424. #define    MACH_RCV_BODY_ERROR        0x1000400c
  425.         /* Error receiving message body.  See special bits. */
  426.  
  427.  
  428. extern mach_msg_return_t
  429. mach_msg_trap
  430. #if    defined(c_plusplus) || defined(__STDC__)
  431.    (mach_msg_header_t *msg,
  432.     mach_msg_option_t option,
  433.     mach_msg_size_t send_size,
  434.     mach_msg_size_t rcv_size,
  435.     mach_port_t rcv_name,
  436.     mach_msg_timeout_t timeout,
  437.     mach_port_t notify);
  438. #else    /* c_plusplus || __STDC__ */
  439. #ifdef    LINTLIBRARY
  440.    (msg, option, send_size, rcv_size, rcv_name, timeout, notify)
  441.     mach_msg_header_t *msg;
  442.     mach_msg_option_t option;
  443.     mach_msg_size_t send_size;
  444.     mach_msg_size_t rcv_size
  445.     mach_port_t rcv_name;
  446.     mach_msg_timeout_t timeout;
  447.     mach_port_t notify;
  448. { return MACH_RCV_SUCCESS; }
  449. #else    /* LINTLIBRARY */
  450.    ();
  451. #endif    /* LINTLIBRARY */
  452. #endif    /* c_plusplus || __STDC__ */
  453.  
  454. extern mach_msg_return_t
  455. mach_msg
  456. #if    defined(c_plusplus) || defined(__STDC__)
  457.    (mach_msg_header_t *msg,
  458.     mach_msg_option_t option,
  459.     mach_msg_size_t send_size,
  460.     mach_msg_size_t rcv_size,
  461.     mach_port_t rcv_name,
  462.     mach_msg_timeout_t timeout,
  463.     mach_port_t notify);
  464. #else    /* c_plusplus || __STDC__ */
  465. #ifdef    LINTLIBRARY
  466.    (msg, option, send_size, rcv_size, rcv_name, timeout, notify)
  467.     mach_msg_header_t *msg;
  468.     mach_msg_option_t option;
  469.     mach_msg_size_t send_size;
  470.     mach_msg_size_t rcv_size
  471.     mach_port_t rcv_name;
  472.     mach_msg_timeout_t timeout;
  473.     mach_port_t notify;
  474. { return MACH_RCV_SUCCESS; }
  475. #else    /* LINTLIBRARY */
  476.    ();
  477. #endif    /* LINTLIBRARY */
  478. #endif    /* c_plusplus || __STDC__ */
  479.  
  480.  
  481. /* Definitions for the old IPC interface. */
  482.  
  483. /*
  484.  *    Message data structures.
  485.  *
  486.  *    Messages consist of two parts: a fixed-size header, immediately
  487.  *    followed by a variable-size array of typed data items.
  488.  *
  489.  */
  490.  
  491. typedef    unsigned int    msg_size_t;
  492.  
  493. typedef    struct {
  494.         unsigned int    msg_unused : 24,
  495.                 msg_simple : 8;
  496.         msg_size_t    msg_size;
  497.         integer_t    msg_type;
  498.         port_t        msg_local_port;
  499.         port_t        msg_remote_port;
  500.         integer_t    msg_id;
  501. } msg_header_t;
  502.  
  503. #define MSG_SIZE_MAX    8192
  504.  
  505. /*
  506.  *    Known values for the msg_type field.
  507.  *    These are Accent holdovers, which should be purged when possible.
  508.  *
  509.  *    Only one bit in the msg_type field is used by the kernel.
  510.  *    Others are available to user applications.  See <msg_type.h>
  511.  *    for system application-assigned values.
  512.  */
  513.  
  514. #define MSG_TYPE_NORMAL        0
  515. #define MSG_TYPE_EMERGENCY    1
  516.  
  517. /*
  518.  *    Each data item is preceded by a description of that
  519.  *    item, including what type of data, how big it is, and
  520.  *    how many of them are present.
  521.  *
  522.  *    The actual data will either follow this type
  523.  *    descriptor ("inline") or will be specified by a pointer.
  524.  *
  525.  *    If the type name, size, or number is too large to be encoded
  526.  *    in this structure, the "longform" option may be selected,
  527.  *    and those fields must immediately follow in full integer fields.
  528.  *
  529.  *    For convenience, out-of-line data regions or port rights may
  530.  *    be deallocated when the message is sent by specifying the
  531.  *    "deallocate" field.  Beware: if the data item in question is both
  532.  *    out-of-line and contains port rights, then both will be deallocated.
  533.  */
  534.  
  535. typedef struct  {
  536.     unsigned int    msg_type_name : 8,        /* What kind of data */
  537.             msg_type_size : 8,        /* How many bits is each item */
  538.             msg_type_number : 12,        /* How many items are there */
  539.             msg_type_inline : 1,        /* If true, data follows; else a pointer */
  540.             msg_type_longform : 1,        /* Name, size, number follow: see above */
  541.             msg_type_deallocate : 1,    /* Deallocate port rights or memory */
  542.             msg_type_unused : 1;
  543. } msg_type_t;
  544.  
  545. typedef    struct    {
  546.     msg_type_t    msg_type_header;
  547.     unsigned short    msg_type_long_name;
  548.     unsigned short    msg_type_long_size;
  549.     natural_t    msg_type_long_number;
  550. } msg_type_long_t;
  551.  
  552. /*
  553.  *    Known values for the msg_type_name field.
  554.  *
  555.  *    The only types known to the Mach kernel are
  556.  *    the port types, and those types used in the
  557.  *    kernel RPC interface.
  558.  */
  559.  
  560. #define MSG_TYPE_UNSTRUCTURED    0
  561. #define MSG_TYPE_BIT        0
  562. #define MSG_TYPE_BOOLEAN    0
  563. #define MSG_TYPE_INTEGER_16    1
  564. #define MSG_TYPE_INTEGER_32    2
  565. #define MSG_TYPE_PORT_OWNERSHIP    3    /* obsolete */
  566. #define MSG_TYPE_PORT_RECEIVE    4    /* obsolete */
  567. #define MSG_TYPE_PORT_ALL    5
  568. #define MSG_TYPE_PORT        6
  569. #define MSG_TYPE_CHAR        8
  570. #define MSG_TYPE_BYTE        9
  571. #define MSG_TYPE_INTEGER_8    9
  572. #define MSG_TYPE_REAL        10
  573. #define MSG_TYPE_STRING        12
  574. #define MSG_TYPE_STRING_C    12
  575. /*    MSG_TYPE_INVALID    13    unused */
  576.  
  577. #ifdef    KERNEL
  578. #define MSG_TYPE_INTERNAL_MEMORY 14
  579. #else    KERNEL
  580. #define MSG_TYPE_INTERNAL_MEMORY MSG_TYPE_INTEGER_8
  581. #endif    KERNEL
  582.  
  583. #define MSG_TYPE_PORT_NAME    15        /* A capability name */
  584. #define MSG_TYPE_LAST        16        /* Last assigned */
  585.  
  586. #define MSG_TYPE_POLYMORPHIC    ((unsigned int) -1)
  587.  
  588. /*
  589.  *    Is a given item a port type?
  590.  */
  591.  
  592. #define MSG_TYPE_PORT_ANY(x)    \
  593.     (((x) == MSG_TYPE_PORT) || ((x) == MSG_TYPE_PORT_ALL))
  594.  
  595. /*
  596.  *    Other basic types
  597.  */
  598.  
  599. typedef natural_t    msg_timeout_t;
  600.  
  601. /*
  602.  *    Options to IPC primitives.
  603.  *
  604.  *    These can be combined by or'ing; the combination RPC call
  605.  *    uses both SEND_ and RCV_ options at once.
  606.  */
  607.  
  608. typedef    integer_t        msg_option_t;
  609.  
  610. #define MSG_OPTION_NONE    0x0000    /* Terminate only when message op works */
  611.  
  612. #define SEND_TIMEOUT    0x0001    /* Terminate on timeout elapsed */
  613. #define SEND_NOTIFY    0x0002    /* Terminate with reply message if need be */
  614.  
  615. #define SEND_INTERRUPT    0x0004    /* Terminate on software interrupt */
  616.  
  617. #define SEND_SWITCH    0x0020    /* Use handoff scheduling */
  618.  
  619. #ifdef    KERNEL
  620. #define SEND_ALWAYS    0x0008    /* Never block */
  621. /*    SEND_KERNEL    0x0010       Kernel is originator (not used) */
  622. #define    SEND_USER    (SEND_TIMEOUT|SEND_NOTIFY|SEND_SWITCH)
  623.                 /* Valid user options */
  624. #define SEND_SWITCH    0x0020    /* Use handoff scheduling */
  625. #endif    KERNEL
  626.  
  627. #define RCV_TIMEOUT    0x0100    /* Terminate on timeout elapsed */
  628. #define RCV_NO_SENDERS    0x0200    /* Terminate if I'm the only sender left */
  629. #define RCV_INTERRUPT    0x0400    /* Terminate on software interrupt */
  630. #define RCV_LARGE    0x1000
  631.  
  632. #ifdef    KERNEL
  633. #define RCV_USER    (RCV_TIMEOUT|RCV_NO_SENDERS|RCV_INTERRUPT|RCV_LARGE)
  634. #endif    KERNEL
  635.  
  636. /*
  637.  *    Returns from IPC primitives.
  638.  *
  639.  *    Values are separate in order to allow RPC users to
  640.  *    distinguish which operation failed; for successful completion,
  641.  *    this doesn't matter.
  642.  */
  643.  
  644. typedef    int        msg_return_t;
  645.  
  646. #define SEND_SUCCESS        0
  647.  
  648. #define SEND_ERRORS_START    -100
  649. #ifdef    KERNEL
  650. #define SEND_IN_PROGRESS    -100
  651. #endif    KERNEL
  652. #define SEND_INVALID_MEMORY    -101    /* Message or OOL data invalid */
  653. #define SEND_INVALID_PORT    -102    /* Reference to inacessible port */
  654. #define SEND_TIMED_OUT        -103    /* Terminated due to timeout */
  655. #define SEND_WILL_NOTIFY    -105    /* Msg accepted provisionally */
  656. #define SEND_NOTIFY_IN_PROGRESS    -106    /* Already awaiting a notification */
  657. #define SEND_KERNEL_REFUSED    -107    /* Message to the kernel refused */
  658. #define SEND_INTERRUPTED    -108    /* Software interrupt during send */
  659. #define SEND_MSG_TOO_LARGE    -109    /* Message specified was too large */
  660. #define SEND_MSG_TOO_SMALL    -110    /* Data specified exceeds msg size */
  661. /*    SEND_MSG_SIZE_CHANGE    -111       Msg size changed during copy */
  662. #define SEND_ERRORS_END        -111
  663.  
  664. #define msg_return_send(x)    ((x) < SEND_ERRORS_START && (x) > SEND_ERRORS_END)
  665.  
  666. #define RCV_SUCCESS        0
  667.  
  668. #define RCV_ERRORS_START    -200
  669. #ifdef    KERNEL
  670. #define RCV_IN_PROGRESS        -200
  671. #endif    KERNEL
  672. #define RCV_INVALID_MEMORY    -201
  673. #define RCV_INVALID_PORT    -202
  674. #define RCV_TIMED_OUT        -203
  675. #define RCV_TOO_LARGE        -204    /* Msg structure too small for data */
  676. #define RCV_NOT_ENOUGH_MEMORY    -205    /* Can't find space for OOL data */
  677. #define RCV_ONLY_SENDER        -206    /* Receiver is only sender */
  678. #define RCV_INTERRUPTED        -207
  679. #define RCV_PORT_CHANGE        -208    /* Port was put in a set */
  680. #define RCV_ERRORS_END        -209
  681.  
  682. #define msg_return_rcv(x)    ((x) < RCV_ERRORS_START && (x) > RCV_ERRORS_END)
  683.  
  684. #define RPC_SUCCESS        0
  685.  
  686. /*
  687.  *    The IPC primitive functions themselves
  688.  */
  689.  
  690. msg_return_t    msg_send(
  691. #if    defined(c_plusplus) || defined(__STDC__)
  692.     msg_header_t    *header,
  693.     msg_option_t    option,
  694.     msg_timeout_t    timeout);
  695. #else    /* c_plusplus || __STDC__ */
  696. #if    LINTLIBRARY
  697.             header, option, timeout)
  698.     msg_header_t    *header;
  699.     msg_option_t    option;
  700.     msg_timeout_t    timeout;
  701.     { return(SEND_SUCCESS); }
  702. #else    /* LINTLIBRARY */
  703.         );
  704. #endif    /* LINTLIBRARY */
  705. #endif    /* c_plusplus || __STDC__ */
  706.  
  707. msg_return_t    msg_receive(
  708. #if    defined(c_plusplus) || defined(__STDC__)
  709.     msg_header_t    *header,
  710.     msg_option_t    option,
  711.     msg_timeout_t    timeout);
  712. #else    /* c_plusplus || __STDC__ */
  713. #if    LINTLIBRARY
  714.             header, option, timeout)
  715.     msg_header_t    *header;
  716.     msg_option_t    option;
  717.     msg_timeout_t    timeout;
  718.     { return(RCV_SUCCESS); }
  719. #else    /* LINTLIBRARY */
  720.         );
  721. #endif    /* LINTLIBRARY */
  722. #endif    /* c_plusplus || __STDC__ */
  723.  
  724. msg_return_t    msg_rpc(
  725. #if    defined(c_plusplus) || defined(__STDC__)
  726.     msg_header_t    *header,    /* in/out */
  727.     msg_option_t    option,
  728.     msg_size_t    rcv_size,
  729.     msg_timeout_t    send_timeout,
  730.     msg_timeout_t    rcv_timeout);
  731. #else    /* c_plusplus || __STDC__ */
  732. #if    LINTLIBRARY
  733.             header, option, rcv_size,
  734.             send_timeout, rcv_timeout)
  735.     msg_header_t    *header;    /* in/out */
  736.     msg_option_t    option;
  737.     msg_size_t    rcv_size;
  738.     msg_timeout_t    send_timeout;
  739.     msg_timeout_t    rcv_timeout;
  740.     { return(RPC_SUCCESS); }
  741. #else    /* LINTLIBRARY */
  742.         );
  743. #endif    /* LINTLIBRARY */
  744. #endif    /* c_plusplus || __STDC__ */
  745.  
  746. msg_return_t    msg_send_trap(
  747. #if    defined(c_plusplus) || defined(__STDC__)
  748.     msg_header_t    *header,
  749.     msg_option_t    option,
  750.     msg_size_t    send_size,
  751.     msg_timeout_t    timeout);
  752. #else    /* c_plusplus || __STDC__ */
  753. #if    LINTLIBRARY
  754.             header, option, send_size, timeout)
  755.     msg_header_t    *header;
  756.     msg_option_t    option;
  757.     msg_size_t    send_size;
  758.     msg_timeout_t    timeout;
  759.     { return(SEND_SUCCESS); }
  760. #else    /* LINTLIBRARY */
  761.         );
  762. #endif    /* LINTLIBRARY */
  763. #endif    /* c_plusplus || __STDC__ */
  764.  
  765. msg_return_t    msg_receive_trap(
  766. #if    defined(c_plusplus) || defined(__STDC__)
  767.     msg_header_t    *header,
  768.     msg_option_t    option,
  769.     msg_size_t    rcv_size,
  770.     port_name_t    rcv_name,
  771.     msg_timeout_t    timeout);
  772. #else    /* c_plusplus || __STDC__ */
  773. #if    LINTLIBRARY
  774.             header, option, rcv_size, rcv_name, timeout)
  775.     msg_header_t    *header;
  776.     msg_option_t    option;
  777.     msg_size_t    rcv_size;
  778.     port_name_t    rcv_name;
  779.     msg_timeout_t    timeout;
  780.     { return(RCV_SUCCESS); }
  781. #else    /* LINTLIBRARY */
  782.         );
  783. #endif    /* LINTLIBRARY */
  784. #endif    /* c_plusplus || __STDC__ */
  785.  
  786. msg_return_t    msg_rpc_trap(
  787. #if    defined(c_plusplus) || defined(__STDC__)
  788.     msg_header_t    *header,    /* in/out */
  789.     msg_option_t    option,
  790.     msg_size_t    send_size,
  791.     msg_size_t    rcv_size,
  792.     msg_timeout_t    send_timeout,
  793.     msg_timeout_t    rcv_timeout);
  794. #else    /* c_plusplus || __STDC__ */
  795. #if    LINTLIBRARY
  796.             header, option, send_size, rcv_size,
  797.             send_timeout, rcv_timeout)
  798.     msg_header_t    *header;    /* in/out */
  799.     msg_option_t    option;
  800.     msg_size_t    send_size;
  801.     msg_size_t    rcv_size;
  802.     msg_timeout_t    send_timeout;
  803.     msg_timeout_t    rcv_timeout;
  804.     { return(RPC_SUCCESS); }
  805. #else    /* LINTLIBRARY */
  806.         );
  807. #endif    /* LINTLIBRARY */
  808. #endif    /* c_plusplus || __STDC__ */
  809.  
  810. #endif    /* _MACH_MESSAGE_H_ */
  811.